import pygame
from pygame import Rect

import main.TankBattle as TankBattle


class Wall(pygame.sprite.Sprite):

    def __init__(self, screen, top, left, width, height):
        pygame.sprite.Sprite.__init__(self)
        self.screen = screen
        self.rect = Rect(left, top, width, height)
        self.color = (255, 0, 0)

    def draw(self):
        # self.screen.fill(self.color, self.rect)
        pygame.draw.rect(self.screen, self.color, self.rect, 5)

    def _collide_other(self, other):
        return pygame.sprite.collide_rect(self, other)

    def collide_wall(self):
        for player in TankBattle.TankBattle.players:
            if self._collide_other(player):
                player.stop = True
                player.reset_play()

            for missile in player.missiles:
                if self._collide_other(missile):
                    player.missiles.remove(missile)

        for enemy in TankBattle.TankBattle.enemys:
            if self._collide_other(enemy):
                enemy.stop = True
                enemy.reset_play()

            for missile in enemy.missiles:
                if self._collide_other(missile):
                    enemy.missiles.remove(missile)
